package com.sherlockHolmes.init.controller;

import com.sherlockHolmes.init.base.result.Ajax;
import com.sherlockHolmes.init.entity.dao.Community;
import com.sherlockHolmes.init.entity.dto.ApproveCommunityDTO;
import com.sherlockHolmes.init.service.CommunityService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/community")
public class CommunityController {
    @Resource
    private CommunityService communityService;
    /**
     * 创建社区
     */
    @PostMapping("/create")
    public Ajax createCommunity(@RequestBody Community community, HttpServletRequest request){
        try{
            return Ajax.success(communityService.addCommunity(community,request));
        }catch (Exception e){
            return Ajax.fail(e);
        }
    }
    /**
     * 申请加入社区
     */
    @PostMapping("/apply")
    public Ajax applyCommunity(@RequestParam Integer communityId, HttpServletRequest request){
        try{
            return Ajax.success(communityService.applyCommunity(communityId,request));
        }catch (Exception e){
            return Ajax.fail(e);
        }
    }
    /**
     * 审批申请
     */
    @PostMapping("/approve")
    public Ajax approveCommunity(@RequestBody ApproveCommunityDTO approveCommunityDTO, HttpServletRequest request){
        try{
            return Ajax.success(communityService.approveCommunity(approveCommunityDTO,request));
        }catch (Exception e){
            return Ajax.fail(e);
        }
    }
    /**
     * 解散社区
     */
    @DeleteMapping("/dissolveTheCommunity")
    public Ajax dissolveTheCommunity(@RequestParam Integer communityId, HttpServletRequest request){
        try{
            return Ajax.success(communityService.dissolveTheCommunity(communityId,request));
        }catch (Exception e){
            return Ajax.fail(e);
        }
    }

}
